package android.Spider;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;

public class ThreadCreate extends Activity
{

	@Override
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		
		m_idTopic = getIntent().getIntExtra(MessageBoard.s_strTopic, -1);
		m_connection.Initialize(this);
		
		setContentView(R.layout.threadcreate);
		
		final int nAvatar = SpiderPreferences.Instance(this).GetUserProfile().m_nAvatar;
		((ImageView)findViewById(R.id.ThreadCreationAvatarImage)).setImageResource(ProfileUser.idImages[nAvatar]);
	}

	@Override
	protected void onDestroy() {
		m_connection.Unregister();
		super.onDestroy();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    super.onCreateOptionsMenu(menu);
	    
	    menu.add(0, 0, "Submit", R.drawable.submitsend);
	    menu.add(0, 1, "Discard", R.drawable.discard);
	    return true;
	}

	@Override
	public boolean onOptionsItemSelected(Menu.Item item)
	{
	    if (item.getId() == 0)
	    {
	    	String strTitle = ((TextView)findViewById(R.id.ThreadCreationTitle)).getText().toString();
	    	String strText = ((TextView)findViewById(R.id.ThreadCreationText)).getText().toString();
	    	m_connection.CreateTopicThread(m_idTopic, strTitle, strText);
		    finish();
	    	return true;
	    }
	    else if (item.getId() == 1)
	    {
	    	finish();
	    	return true;
	    }
	    
	    return false;
	}
	
	private int m_idTopic;
    private XmppConnection m_connection = new XmppConnection() { };

}
